﻿using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Logic.Services.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;
using MaxStoreShop.Logic.Tests.FakeRepositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MaxStoreShop.Logic.Tests
{
    [TestClass]
    public class MeasureTypeServiceTests
    {
        [TestMethod]
        public void DeleteMeasureShouldNormal()
        {
            CreateInstance().DeleteMeasure(new MeasureType {Id = 1});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void DeleteMeasureShouldThrowErpRuntimeExceptionIfTypeIsNull()
        {
            CreateInstance().DeleteMeasure(null);
        }

        [TestMethod]
        public void SaveMeasureShouldNormal()
        {
            CreateInstance().SaveMeasure(new MeasureType {Name = "Килограмм", ShortName = "кг"});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveMeasureShouldThrowErpRuntimeExceptionIfTypeIsNull()
        {
            CreateInstance().SaveMeasure(null);
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveMeasureTypeShouldThrowErpRuntimeExceptionIfTypeNameIsNullOrEmpty()
        {
            CreateInstance().SaveMeasure(new MeasureType {Name = null, ShortName = "кг"});
        }
        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveMeasureTypeShouldThrowErpRuntimeExceptionIfTypeShortNameIsNullOrEmpty()
        {
            CreateInstance().SaveMeasure(new MeasureType {Name = "Килограмм", ShortName = null});
        }

        static IMeasureTypeService CreateInstance()
        {
            return new MeasureTypeService(new MeasureTypeRepositoryFake());
        }
    }
}
